

import 'package:FiduMart/core/utils/image_constant.dart';
import 'package:FiduMart/screen/home/QuotesController.dart';
import 'package:flutter/material.dart';

import '../../localization/app_export.dart';

class CurrencySearch extends GetWidget<QuotesController> {

  final controller = Get.put(QuotesController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body:SingleChildScrollView(
        child:  Column(
          children: [
            SizedBox(
              height: 30,
            ),
            buildTitle(context),
            searchTitle(context),
            Obx(() => listMainUI(context)),
          ],
        ),
      )
    );
  }

  Widget buildTitle(BuildContext context) {
    return Row(
      children: [
        SizedBox(
          width: 10,
        ),
        IconButton(
          icon: Icon(
            Icons.arrow_back_ios,
            size: 24,
            color: Colors.black,
          ),
          onPressed: () {
            Get.back();
          },
        ),
        Expanded(
            child: Center(
                child: Text(
                    "search_currency".tr,
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                        fontSize: 18,
                        fontWeight: FontWeight.bold,
                        color: Colors.black)))),
        SizedBox(
          width: 50,
        ),
      ],
    );
  }
  
  Widget searchTitle(BuildContext context){
    return Container(
      margin: EdgeInsets.only(left: 10),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          // Text('home_list'.tr,style: TextStyle(fontSize: 16,color: ColorConstant.colorFF23262F),),
          Expanded(child:
          GestureDetector(
            child: Container(
              padding: EdgeInsets.only(left: 10,right: 10),
              height: 44,
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  colors: [ColorConstant.whiteA700,ColorConstant.whiteA700],
                  begin: FractionalOffset.centerLeft,
                  end: FractionalOffset.centerRight,
                ),
                borderRadius: BorderRadius.circular(4),
                border:  Border.all(color: ColorConstant.colorFFCCCCCC, width: 1),
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  CustomImageView(
                    imagePath: "assets/images/icon_mark_search.png",
                    width: 20,
                    height: 20,
                  ),
                  SizedBox(width: 5,),
                  Container(
                    width: 220,
                    child: TextField(
                      controller: controller.inputController,
                      style: TextStyle(color: ColorConstant.colorFF23262F),
                      onChanged: (value) {
                        controller.queryString.value = value.toString();
                      },
                      decoration: InputDecoration(
                        hintText: "search_currency".tr,
                        border: InputBorder.none,
                        hintStyle: TextStyle(color: ColorConstant.colorFF23262F.withOpacity(0.5)),
                        contentPadding: EdgeInsets.symmetric(vertical: 10.0), // 内边距调整
                      ),
                    ),
                  ),
                  GestureDetector(
                    onTap: (){
                      controller.currencySearchClear();
                    },
                    child: CustomImageView(
                      imagePath: "assets/images/icon_mark_close.png",
                      width: 20,
                      height: 20,
                    ),
                  ),
                ],
              ),
            ),
          )
          ),
          Container(
            width: 60,
            height: 44,
            child: GestureDetector(
              onTap: (){
                FocusScope.of(context).unfocus();
                controller.currencySearch();
              },
              child: Center(
                child: Text('search_title'.tr,style: TextStyle(
                  color: ColorConstant.colorFF40EA93, // 文字颜色
                  fontSize: 16, // 文字大小
                )),
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget listMainUI(BuildContext context) {
    return Flex(
      direction: Axis.vertical,
      children: [
        controller.associationProjectList.length == 0 ? Container(
            width: MediaQuery.of(context).size.width,
            height: MediaQuery.of(context).size.height-150,
            child:Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  CustomImageView(
                    imagePath: ImageConstant.noDate,
                    width: 134,
                    height: 134,
                  ),

                  Text('no_relevant_data_yet'.tr,
                    style: TextStyle(
                      color: ColorConstant.colorFF23262F, // 文字颜色
                      fontSize: 12, // 文字大小
                    ),
                  ),
                ],
              ),
            )):
        buildList()
      ],
    );


  }


  ListView buildList() {
    return ListView.builder(
        padding: EdgeInsets.zero,
        itemCount: controller.associationProjectList.length,
        physics: NeverScrollableScrollPhysics(),
        shrinkWrap: true,
        itemBuilder: (BuildContext context, int index) {
          return GestureDetector(
            onTap: (){
              controller.getCurrencyrankItem(associationProject:controller.associationProjectList[index]);
            },
            child: Container(
              margin: EdgeInsets.only(top: 15,left: 10,right: 10),
              padding: EdgeInsets.only(top: 5,bottom: 5,right: 8),
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  colors: [ColorConstant.colorFFF2F2F7,ColorConstant.colorFFF2F2F7],
                  begin: FractionalOffset.centerLeft,
                  end: FractionalOffset.centerRight,
                ),
                borderRadius: BorderRadius.circular(16),
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Row(
                    children: [
                      CustomImageView(
                        url: controller.associationProjectList[index].logo.toString(),
                        fit: BoxFit.fill,
                        width: 48,
                        height: 48,
                        margin:EdgeInsets.all(10) ,
                        radius: BorderRadius.circular(24),
                      ),
                      Column(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text(controller.associationProjectList[index].name.toString(),
                              style: TextStyle(
                                color: ColorConstant.colorFF23262F, // 文字颜色
                                fontSize: 16, // 文字大小
                              )),
                          Text(controller.investList[index].symbol.toString(),
                              style: TextStyle(
                                color: ColorConstant.colorFF828A99, // 文字颜色
                                fontSize: 12, // 文字大小
                              )),
                        ],
                      )
                    ],
                  ),
                  Row(
                    children: [
                      Column(
                        mainAxisAlignment: MainAxisAlignment.end,
                        crossAxisAlignment: CrossAxisAlignment.end,
                        children: [

                        ],
                      )
                    ],
                  )
                ],
              ),
            ),
          ) ;
        }
    );
  }


}
